<?php defined( '_JEXEC' ) or die( 'Restricted access' );

class sketchup_html
{
	/**
	 * Creates the ratingbar
	 *
	 * @param array $item
	 * @since 1.0
	 */
	function ratingbar($project)
	{
		JHTML::_('behavior.tooltip');

		//sql calculation doesn't work with negative values and thus only minus votes will not be taken into account
		if ($this->project->votes == 0 && $this->project->minus != 0) {
			return JText::sprintf('RATED NEGATIVE', $this->project->minus);
		} elseif ($this->project->votes == 0 && $this->project->minus == 0) {
			return JText::_('NOT YET RATED');
		}

		//we do the rounding here and not in the query to get better ordering results
		$rating = round($this->project->votes);

		$output = '<span class="qf_ratingbarcontainer editlinktip hasTip" title="'.JText::_('RATING').'::'.JText::_('USEFULLNESS').': '.$rating.'%&lt;br /&gt;'.JText::_('GOOD').': '.$this->project->plus.'&lt;br /&gt;'.JText::_('BAD').': '.$this->project->minus.'">';
		$output .= '<span class="qf_ratingbar" style="width:'.$rating.'%;">&nbsp;</span></span>';

		return $output;
	}


	/**
	 * Creates the voteicons
	 *
	 * @param array $params
	 * @since 1.0
	 */
	function voteicons($item, &$params)
	{
		JHTML::_('behavior.tooltip');
		$document 	= & JFactory::getDocument();
		
		// ( $params->get('show_icons') ) {
			$voteup = JHTML::_('image.site', 'thumb_up.png', 'components/com_sketchup/assets/images/', NULL, NULL, JText::_( 'GOOD' ) );
			$votedown = JHTML::_('image.site', 'thumb_down.png', 'components/com_sketchup/assets/images/', NULL, NULL, JText::_( 'BAD' ) );
		//} else {
		//	$voteup = JText::_( 'GOOD' ). '&nbsp;';
		//	$votedown = '&nbsp;'.JText::_( 'BAD' );
		//}
		
		$js = 'function voting(vote) {
				if (vote == 1) {
					location = "'.JRoute::_("index.php?task=vote&vote=1&cid=".$this->project->id."&id=".$this->project->id).'";
				} else {
					location = "'.JRoute::_("index.php?task=vote&vote=0&id=".$this->sketchup_id).'";
				}}';
		$document->addScriptDeclaration($js);

		$output = '<a href="#" class="editlinktip hasTip" title="'.JText::_( 'VOTE UP' ).'::'.JText::_( 'VOTE UP TIP' ).'" rel="nofollow" onclick="voting(1)">'.$voteup.'</a>';
		$output .= ' - ';
		$output .= '<a href="#" class="editlinktip hasTip" title="'.JText::_( 'VOTE DOWN' ).'::'.JText::_( 'VOTE DOWN TIP' ).'" rel="nofollow" onclick="voting(0)">'.$votedown.'</a>';

		return $output;
	}

}//the end
?>